package com.op.teachingliteapp.fragment.resourcedetails;


import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.op.teachingliteapp.R;



public class ResourceDetailsAdapter extends BaseAdapter{
	private ArrayList<ResourceDetailsDataProvider>  list_ppt;
	public  int size;
	 private Context mContext;
	 private TextView ppt_name;
	 private ImageView ppt_img;
	 private TextView ppt_dec;
	 public StringBuffer checkBox_chosen=new StringBuffer();
//	 public CheckBox deleteView;
	 private boolean isShowDelete;//根据这个变量来判断是否显示删除图标，true是显示，false是不显示

	 public ResourceDetailsAdapter(Context mContext,ArrayList<ResourceDetailsDataProvider> list) {
	  this.mContext = mContext;
	  this.list_ppt=list;
	//  list_ppt.add(new ResourceDetailsDataProvider("初次接触Java",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("java语言基础",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("程序工程规范",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("面向对象上",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("面向对象中",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("面向对象下",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("异常",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("常用类库与工具",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("线程",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("集合类",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("用户界面",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("网络通信", ""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("设计模式",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("软件框架",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	 // list_ppt.add(new ResourceDetailsDataProvider("Web service",""+getContext().getString(R.string.ppt_list_dex),R.drawable.ppt));
	  list_ppt.add(new ResourceDetailsDataProvider("添加PPT","","",android.R.drawable.ic_input_add));
	 }
	 public void setIsShowDelete(boolean isShowDelete){
	  this.isShowDelete=isShowDelete;
	  notifyDataSetChanged();
	 }
	 
		public void add(ResourceDetailsDataProvider lcd){
			list_ppt.add(list_ppt.size()-1,lcd);
            notifyDataSetChanged();
			}
	 
		public Context getContext(){
			return mContext;
		}
	

	 public 	void remove(int position) {
		 list_ppt.remove(position);		
	     notifyDataSetChanged();
		}
	 
	 @Override
	 public int getCount() {
		 return list_ppt.size();
	 }

	 @Override
	 public ResourceDetailsDataProvider getItem(int position) {
		 return list_ppt.get(position);
	 }

	 @Override
	 public long getItemId(int position) {
	  return position;
	 }

	 @SuppressLint({ "ViewHolder", "InflateParams" })
	@Override
	 public View getView(final int position, View convertView, ViewGroup parent) {

		LinearLayout ll=null;
		if(convertView!=null){
			ll=(LinearLayout)convertView;
			}else{
				ll=(LinearLayout)LayoutInflater.from(getContext()).inflate(R.layout.item_resource_details_ppt,null);
			}
		final ResourceDetailsDataProvider data=getItem(position);
		
		
	  ppt_img = (ImageView)ll.findViewById(R.id.ppt_img);
	  ppt_name = (TextView) ll.findViewById(R.id.ppt_name);
	  ppt_dec=(TextView)ll.findViewById(R.id.ppt_dec);
	  
	  ppt_img.setImageResource(data.getIconId());
	  ppt_name.setText(data.getName());
	  ppt_dec.setText(data.getDec());
	  
//	  deleteView = (CheckBox)gl.findViewById(R.id.class_checkbox);
//	  if(position<list.size()-1){
//		  deleteView.setVisibility(isShowDelete?View.VISIBLE:View.GONE);//设置删除按钮是否显示
//		  notifyDataSetChanged();
//	  }
//	  
//	  deleteView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//		  
//		  @Override
//		  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//			  if(isChecked){
//				  Toast.makeText(getContext(),"选中"+position,Toast.LENGTH_SHORT).show();
//				  checkBox_chosen.append(data.name);//记录选择课程
//				  
//			  }else{
//				  Toast.makeText(getContext(),"没有选中"+position,Toast.LENGTH_SHORT).show();
//				  size=checkBox_chosen.indexOf(data.name);
//				  checkBox_chosen.delete(size,size+data.name.length());//删除已选课程
//			  }
//			  
//		  }
//	  });
	  
	  return ll;
	 }

}
